//
//  YKCheckController.m
//  ZBarScan
//
//  Created by QFYK on 2017/5/24.
//  Copyright © 2017年 QF_iOS. All rights reserved.
//

#import "YKCheckController.h"

@interface YKCheckController ()<UITableViewDelegate , UITableViewDataSource>

@end

@implementation YKCheckController
{
    UILabel *_navTitleLb;
    CGFloat _cellHeight;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self sortData];
    [self config];
}

- (void)sortData
{
    AppDelegate *appdelegate = kAppDelegate;
    if (appdelegate.publicProperty.loginModel) {
        if ([appdelegate.publicProperty.loginModel.User_Type isEqualToString:@"GC"]) {
            _userType = GC;
        } else {
            _userType = JXS;
        }
    } else {
        _userType = GZ;
    }
}

- (void)config
{
    self.view.backgroundColor = YKCOLOR_MAIN;
    
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 16, 40, 40)];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    // 自定义标题
//    _navTitleLb = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, kScreenW / 3 * 2, 64)];
//    _navTitleLb.center = CGPointMake(self.view.frame.size.width, _navTitleLb.center.y);
//    _navTitleLb.textColor = [UIColor whiteColor];
//    _navTitleLb.textAlignment = NSTextAlignmentCenter;
//    _navTitleLb.font = FONT(20);
//    [_navTitleLb setText:self.title];
//    _navTitleLb.text = @"查询结果";
//    [self.view addSubview:_navTitleLb];
    
    UIImageView *backGroundImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, kScreenW, kScreenH - 64)];
    backGroundImg.image = [UIImage imageNamed:@"bei_xin_search_bg.jpg"];
    [self.view addSubview:backGroundImg];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, kScreenW, kScreenH - 64) style:UITableViewStyleGrouped];
    _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    _mainTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_mainTableView];
}

-(void)backBtnAction {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
#pragma mark - UITableViewDelegate && UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (_productInfo == nil) {
        return 1;
    }
    switch (_userType) {
        case GZ:
            return 7;
        case GC:
            return 13;
    }
    return 21;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YKCheckCell *cell = [YKPublicCell ykCheckTableView:tableView cellForRowAtIndexPath:indexPath];
    [cell transmitData:_productInfo andUserType:_userType andIndexPath:indexPath];
    [cell backCellHeight:^(CGFloat height) {
        _cellHeight = height;
    }];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return _cellHeight;
}

#pragma mark - UITableView Header && Footer
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}

- (void)goBackAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
